import boqdoc
from _wizard import *
from _page import Page

class Wiz(Wizard):
   def __init__(self):
      Wizard.__init__(self, 'Add Section')

   def __call__(self):
      self.__pgOne = Page(self, "Section Name")
      self.__pgTwo = Page(self, "Insert Before")

      seclist = [ sec.name for sec in wx.GetApp().GetDoc().master.sections ]
      seclist += ["<Insert at end>"]

      self.txtpayment = wx.TextCtrl(self.__pgOne, wx.ID_ANY, "")
      self.txtdesc = wx.TextCtrl(self.__pgOne, wx.ID_ANY, "")
      self.lstsections = wx.ListBox(self.__pgTwo, wx.ID_ANY, choices=seclist)

      self.__pgOne.AddWidget(wx.StaticText(self.__pgOne, wx.ID_ANY,
            "Enter the payment text of the new section"))
      self.__pgOne.AddWidget(self.txtpayment)
      self.__pgOne.AddWidget(wx.StaticText(self.__pgOne, wx.ID_ANY,
            "Enter the description text of the new section"))
      self.__pgOne.AddWidget(self.txtdesc)
      self.__pgOne.SetNext(self.__pgTwo)

      self.__pgTwo.AddWidget(wx.StaticText(self.__pgTwo, wx.ID_ANY, "Insert before"))
      self.__pgTwo.AddWidget(self.lstsections)
      self.__pgTwo.SetPrev(self.__pgOne)

      return self.RunWizard(self.__pgOne)

   def complete(self):
      beforesec = self.lstsections.GetSelections()
      beforesec += (len(wx.GetApp().GetDoc().master.sections), 0)
      section = boqdoc.Section(self.txtpayment.GetValue(), self.txtdesc.GetValue())
      doc().master.sections.insert(beforesec[0], section)
